<template>
	<view class="page">
		
		<view class="list">
			<view class="item">
				<input class="input" type="text" placeholder="请输入手机号" v-model="params.mobile" />
			</view>
			<view class="item">
				<input class="input" type="text" placeholder="请输入验证码" v-model="params.code" />
				<text class="getCode" @click="getCode">
					{{text}}
				</text>
			</view>
			<view class="item">
				<input class="input" :password="!showPassword" placeholder="请输入新密码" v-model="params.password" />
				<u-icon :name="showPassword?'eye-fill':'eye-off'" color="#999" @click="showPassword = !showPassword"></u-icon>
			</view>
			<view class="item">
				<input class="input" :password="!showRepassword" placeholder="请确认新密码" v-model="params.repassword" />
				<u-icon :name="showRepassword?'eye-fill':'eye-off'" color="#999" @click="showRepassword = !showRepassword"></u-icon>
			</view>
			<view class="logout" @click="resetSubmit">
				完成
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isPassword:true,
				showNext: false,
				showOldpassword:false,
				showPassword:false,
				showRepassword:false,
				mobile: '',
				showMobile: '',
				code: '',
				model: {
					mobile: '',
					code: ''
				},
				params:{},
				text: '获取验证码',
				userInfo:{}
			}
		},
		methods: {
			go(url) {
				uni.navigateTo({
					url: url
				})
			},
			toPhone(){
				this.isPassword = false
				this.showPassword = false
				this.showRepassword = false
			},
			//验证码倒计时
			getCode() {
				if (this.text == '获取验证码' || this.text == '重新获取') {
					this.rq.getData('sms/send', {
						mobile: this.params.mobile,
						event: 'forgetPassword',
					}).then((res) => {
						let n = 60;
						this.text = "剩余 " + n + "s";
						const run = setInterval(() => {
							n = n - 1;
							this.text = "剩余 " + n + "s";
							if (n < 1) {
								clearInterval(run);
								this.text = "重新获取";
							}
						}, 1000);
					});
				}
			},
			next(){
				this.rq.getData('user/oldMobile',{
					mobile:this.mobile,
					code:this.code
				}).then(res=>{
					if(res.code === 1){
						this.text = '获取验证码'
						this.showNext = true
					}
				})
			},
			submit() {
				if(this.model.password!=this.model.repassword){
					uni.showToast({
						title:'两次密码不符，请确认~',
						icon:'none'
					})
					return
				}
				this.rq.getData('user/changePassword',this.model).then(res=>{
					if(res.code === 1){					
						uni.showToast({
							title:'修改成功~',
							icon:'none'
						})
						setTimeout(()=>{
							uni.navigateBack()
						},500)
					}
				})
			},
			resetSubmit(){
				if(this.params.password!=this.params.repassword){
					uni.showToast({
						title:'两次密码不符，请确认~',
						icon:'none'
					})
					return
				}
				this.rq.getData('user/forgetPwd',this.params).then(res=>{
					if(res.code === 1){					
						uni.showToast({
							title:'修改成功~',
							icon:'none'
						})
						setTimeout(()=>{
							uni.navigateBack()
						},500)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.input{
		border: none;
		width: 480rpx;
		height: 70rpx;
		outline: none;
	}
	.placeholder {
		font-size: 26rpx;
		color: #999999;
	}
	.page {
		height: 100vh;
		overflow: hidden;

		.list {
			padding: 24rpx;

			.item {
				background: #fff;
				height: 92rpx;
				box-sizing: border-box;
				padding: 28rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 20rpx;
				border-radius: 20rpx;
				
				.label {
					font-size: 28rpx;
					color: #333333;
				}

				.content {
					font-size: 26rpx;
					color: #999999;
					margin-top: 24rpx;
				}

				.getCode {
					color: #F7635C;
					font-size: 24rpx;
				}
			}
			
			.tips{
				color: #333333;
				font-size: 28rpx;
				text-align: right;				
				text-decoration: underline;
			}
		}

		.logout {
			margin: 176rpx auto;
			height: 92rpx;
			width: 702rpx;
			border-radius: 100rpx;
			background: #FF5866;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28rpx;
			color: #FFFFFF;
		}
	}
</style>